<template>
<!-- 右侧今日刷题排行榜 -->
<div class="right-sidebar">
    <el-card class="ranking-card">
      <template #header>
        <div class="card-header">
          <span class="title">今日刷题排行榜</span>
          <el-tag type="danger">实时更新</el-tag>
        </div>
      </template>

      <div class="ranking-list">
        <div 
          v-for="(item, index) in rankingData"
          :key="item.id"
          class="ranking-item"
          :class="{ 'top3': index < 3 }"
        >
        <!--数字编号-->
        <span 
            class="rank-number"
            :style="{
              backgroundColor: index < 3 ? '#fdf5e6' : '#f5f7fa',
              color: index < 3 ? '#e6a23c' : '#909399'
            }"
          >
            {{ index + 1 }}
          </span>
          <div class="rank">
            <el-icon v-if="index === 0"><Trophy /></el-icon>
            <el-icon v-else-if="index === 1"><Medal /></el-icon>
            <el-icon v-else-if="index === 2"><Aim /></el-icon>
            <span v-else>{{ index + 1 }}</span>
          </div>
          
          <div class="user-info">
            <el-avatar :size="36" :src="item.avatar" />
            <div class="detail">
              <div class="name">{{ item.name }}</div>
              <div class="meta">
                <span class="department">{{ item.department }}</span>
                <el-tag 
                  v-if="item.progress >= 90"
                  size="mini"
                  type="success"
                >
                  学霸
                </el-tag>
              </div>
            </div>
          </div>

          <div class="stats">
            <div class="count">
              <el-icon><DocumentChecked /></el-icon>
              {{ item.count }}题
            </div>
            <el-progress 
              :percentage="item.accuracy"
              :color="accuracyColor(item.accuracy)"
              :stroke-width="6"
              :show-text="false"
            />
          </div>
        </div>
      </div>

      <el-divider />

      <div class="footer">
        
        <span class="update-time">
          <el-icon><Clock /></el-icon>
          更新于 {{ lastUpdateTime }}
        </span>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { 
  Trophy, Medal, Aim, DocumentChecked, Clock ,
  Top, Bottom
} from '@element-plus/icons-vue'



const props = defineProps({
  rankingData: {
      type: Array,
      required: true
    }
  })


const lastUpdateTime = computed(() => {
  const now = new Date()
  return `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`
})

const accuracyColor = (accuracy) => {
  if (accuracy >= 90) return '#67C23A'// 学霸绿
  if (accuracy >= 80) return '#E6A23C'// 优秀橙
  return '#F56C6C'// 进步红
}

</script>

<style lang="scss" scoped>
.ranking-card {
    margin-top: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);

  :deep(.el-card__header) {
    padding: 16px 20px;
    
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .title {
        font-size: 16px;
        font-weight: 600;
      }
    }
  }

  .ranking-list {

    .rank-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  margin-right: 12px;
  transition: all 0.3s;

  .ranking-item:hover & {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}

    .ranking-item {
      display: flex;
      align-items: center;
      padding: 12px 16px;
      margin-bottom: 8px;
      background: rgba(245, 247, 250, 0.5);
      border-radius: 8px;
      transition: all 0.3s;

      &.top3 {
        background: linear-gradient(90deg, rgba(255,246,222,0.5) 0%, rgba(255,255,255,0.5) 100%);
      }

      &:hover {
        transform: translateX(5px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
      }

      .rank {
        width: 40px;
        text-align: center;
        font-weight: 600;
        color: #F56C6C;
        
        .el-icon {
          font-size: 20px;
          color: #E6A23C;
        }
      }

      .user-info {
        flex: 1;
        display: flex;
        align-items: center;
        min-width: 0;

        .el-avatar {
          margin-right: 12px;
        }

        .detail {
          flex: 1;
          min-width: 0;

          .name {
            font-size: 14px;
            color: #303133;
            margin-bottom: 2px;
          }

          .meta {
            display: flex;
            align-items: center;
            gap: 8px;

            .department {
              font-size: 12px;
              color: #909399;
            }

            .el-tag {
              height: 18px;
              line-height: 18px;
            }
          }
        }
      }

      .stats {
        width: 120px;
        text-align: right;

        .count {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          gap: 4px;
          font-size: 14px;
          color: #606266;
          margin-bottom: 4px;
        }

        .el-progress {
          display: inline-block;
          width: 80px;
        }
      }
    }
  }

  .footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;

    .update-time {
      font-size: 12px;
      color: #909399;
      display: flex;
      align-items: center;
      gap: 4px;
    }
  }
}

@media (max-width: 768px) {
  .ranking-item {
    flex-wrap: wrap;
    padding: 8px !important;

    .user-info {
      flex: 0 0 100%;
      margin-bottom: 8px;
    }

    .stats {
      width: 100% !important;
      text-align: left !important;
    }
  }
}
</style>